import { utilJs } from "@/utils/common.js";
export const appRouterChange = {
  methods: {
    iosAppRouteChange(toPath) {
      const IS_IOS_APP = navigator.userAgent.indexOf("IOSNewApp") > -1;
      const IS_ANDROID_APP = navigator.userAgent.indexOf("APPAndroidLogin") > -1;
      if (IS_IOS_APP) {
        window.webkit.messageHandlers.iosWechatRoute.postMessage(toPath);
      } else if (IS_ANDROID_APP) {
        let data = {
          path: toPath
        }
        window.androidWechatRoute.doAction(JSON.stringify(data))
      } else {
        this.$routerGo(this, "push", { path: toPath });
      }
    },
    cateUrl(cateId1, cateId2, cateId3, name) {
      let toPath = "/";
      toPath = `/homePage/course/catDetailList?cateId1=${cateId1}&cateId2=${cateId2}&cateId3=${cateId3}&name=${name}`
      return toPath;
    },
    goTargetUrl(url) {
      if (!url || url == -1) {
        return;
      }
      let routerPathArr = url.split('#');
      const IS_IOS_APP = navigator.userAgent.indexOf("IOSNewApp") > -1;
      if (IS_IOS_APP && routerPathArr.length > 1) {
        let to = routerPathArr[1];
        this.iosAppRouteChange(to);
        return;
      }
      if (!url.includes("http") && !url.includes("https")) {
        url = "http://" + url;
      }
      let herfArr = url.split("/");
      let herfCompanyId = herfArr.length > 6 && url.split("/")[5].indexOf("#") > -1 ? herfArr[4] : '';
      let curCompanyId = localStorage.getItem('companyId');
      if (herfCompanyId == curCompanyId) {
        let up = url.split('#')[1];
        this.iosAppRouteChange(up);
        return;
      }
      utilJs.locationHref(url, this);
    },
  },
};
